package io.github.biezhi.elves.mapper;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import io.github.biezhi.elves.model.CompAnnualReports;
import io.github.biezhi.elves.qcc.model.CompAnalysis;
import io.github.biezhi.elves.qcc.model.CompBasic;
import io.github.biezhi.elves.qcc.model.CompBasicInfo;
import io.github.biezhi.elves.qcc.model.CompBidDetail;
import io.github.biezhi.elves.qcc.model.CompBidUrlDate;
import io.github.biezhi.elves.qcc.model.CompBidding;
import io.github.biezhi.elves.qcc.model.CompChangeRecord;
import io.github.biezhi.elves.qcc.model.CompQccCrawl;
import io.github.biezhi.elves.qcc.model.CompQuota;
import io.github.biezhi.elves.qcc.model.OutboundInvestment;

public interface QccBidDetailMapper {

	/**
	 * 查询未爬取的公告，即IS_SPIDER=0
	 * @return
	 */
	@Select("select bid_id as bidId,comp_id as compId,comp_name as compName,bidding_title as biddingTitle,"
			+ " bidding_detail_url as biddingDetailUrl,bidding_date as biddingDate"
			+ " from t_comp_bid_url_date where is_spider = 0 limit #{num}")
	public List<CompBidUrlDate> queryCompBidUrlDate(Integer num);
	
	/**
	 * 根据compId更新爬取状态,0表示未爬取，1表示已爬取，2表示爬取异常
	 * @param compId
	 */
	@Update("update t_comp_bid_url_date set is_spider=#{state} where bid_id=#{bidId}")
	void updateCompBidUrlDateState(@Param("bidId") Long bidId,@Param("state") Integer state);

	/**
	 * 将爬取出来的数据存放到数据库表中
	 */
	@Insert("INSERT INTO t_comp_bid_detail (bid_id,comp_id,comp_name, bidding_title,"
			+ " bidding_date, bidding_html,bidding_detail_url) "
			+" VALUES (#{bidId},#{compId},#{compName}, #{biddingTitle},"
			+ " #{biddingDate},#{biddingHtml},#{biddingDetailUrl})")
	public void insertCompBidDetail(CompBidDetail compBidDetail);
	
	
	/**
	 * 通过企业名称查询公告信息
	 * @param compName
	 * @return
	 */
	@Select("select bid_id as bidId,comp_id as compId,comp_name as compName,bidding_title as biddingTitle,"
			+ " bidding_date as biddingDate,bidding_html as biddingHtml"
			+ " from t_comp_bid_detail where comp_name = #{compName}")
	public List<CompBidDetail> queryCompBidDetail(String compName);
	
}
